package com.yupi.project.security;

import cn.hutool.extra.spring.SpringUtil;
import com.yupi.project.model.AuthenticatorResult;
import com.yupi.project.model.ProtectedRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.server.ServerWebExchange;

@Slf4j
public class DefaultApiAuthenticator implements ApiAuthenticator{
    @Override
    public AuthenticatorResult auth(ServerWebExchange request) {
        // 构建校验对象
        ProtectedRequest protectedRequest = ProtectedRequest.builder()
                .request(request.getRequest())
                .build();
        // 获取责任链bean实例
        SecurityVerificationChain securityVerificationChain = SpringUtil.getBean(SecurityVerificationChain.class);
        // 依次校验
        return securityVerificationChain.handler(protectedRequest);
    }
}
